package com.itheima.health.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;
import com.itheima.health.utils.resources.MessageConstant;
import com.itheima.health.vo.SetmealVO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SetmealController {

    @Reference
    private SetmealService setmealService;

    @GetMapping("setmeal/findAll")
    public  Result  findAll(){
        try{
            List<Setmeal> list = setmealService.list();
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,list);
        }catch (Exception e){
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    @GetMapping("setmeal/findSetmealInfoById/{id}")
    public  Result  findSetmealInfoById(@PathVariable("id") int id){
        try{
            Setmeal setmeal = setmealService.getById(id);  //  mp 提供的方法
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        }catch (Exception e){
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    @GetMapping("setmeal/findSetMealDetail/{id}")
    public  Result  findSetMealDetail(@PathVariable("id") int id){
        try{
            SetmealVO setmealVO = setmealService.findSetMealDetail(id);
            //  SetmealVO   套餐基本信息  该套餐对应检查组的信息  以及 检查组对应 检查项信息
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmealVO);
        }catch (Exception e){
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
